const {data,tabData,barData} =require('./src/mock')

const bodyParser = require('body-parser')

module.exports={
    devServer:{
        before:app=>{
            app.use(bodyParser.json())
            app.post('/api/list',(req,res)=>{
                res.send({
                    code:200,
                    data
                })
            })
            app.post('/api/search',(req,res)=>{
                let {value}=(req.body)
                let newdata=data.filter(item=>item.name.includes(value)||item.id.includes(value)||item.user.includes(value)||item.statu.includes(value))
                res.send({
                    code:200,
                    newdata
                })
            })
            app.post('/api/tablelist',(req,res)=>{
                res.send({
                    code:200,
                    data:tabData
                })
            })
            app.post('/api/edit',(req,res)=>{
                let {id}=req.body
                let newData=tabData.find(item=>item.id===id)
                res.send({
                    code:200,
                    data:newData
                })
            })
            app.post('/api/edititem',(req,res)=>{
                let obj=req.body
                let F=tabData.find(item=>item.id===obj.id)
                F.account=obj.account,
                F.nickname=obj.nickname,
                res.send({
                    code:200,
                    data
                })
            })
            app.post('/api/add',(req,res)=>{
                let form=req.body
                data=data.push(form)
                res.send({
                    code:200
                })
            })
            app.post('/api/bardata',(req,res)=>{
                console.log(barData)
                res.send({
                    code:200,
                    data:barData
                })
            })
        }
    }
}

